﻿@model DLM.Web.ViewModel.AccountPageView
@using Microsoft.Web.Helpers;
@using Webdiyer.WebControls.Mvc;
@{
    ViewBag.Title = "都来米-会员注册";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#ddlProvince option:first').attr('selected', 'selected');
        $("#txtAccount").blur(function () {
            var account = $("#txtAccount").val();
            if (account != "" && account.length >= 6) {
                var request = $.ajax({
                    url: "/Account/CheckAccount",
                    type: "POST",
                    data: { account: $("#txtAccount").val() }
                });

                request.done(function (msg) {
                    var errorElement = $("#accountError");
                    if (msg == "True") {
                        if (errorElement) {
                            errorElement.removeClass("field-validation-valid");
                            errorElement.addClass("field-validation-error");
                            errorElement.append('<span htmlfor="txtAccount" generated="true" class="" style="">该昵称已经存在</span>');
                            errorElement.show();
                            $("#txtAccount").attr("class", "text t_3 input-validation-error");
                        }
                    } else {
                        $("#txtAccount").attr("class", "text t_3");
                        errorElement.children().remove();
                        errorElement.hide()
                    }
                });

                request.fail(function (jqXHR, textStatus) {
                    ShowDialogMessage("warn", textStatus);
                });
            }

        });

        $("#txtEmail").blur(function () {
            var account = $("#txtEmail").val();
            if (account != "") {
                var request = $.ajax({
                    url: "/Account/CheckEmail",
                    type: "POST",
                    data: { email: $("#txtEmail").val() }
                });

                request.done(function (msg) {
                    var errorElement = $("#emailError");
                    if (msg == "True") {
                        if (errorElement) {
                            errorElement.removeClass("field-validation-valid");
                            errorElement.addClass("field-validation-error");
                            errorElement.append('<span htmlfor="txtEmail" generated="true" class="" style="">该邮箱已经被注册过</span>');
                            errorElement.show();
                            $("#txtEmail").attr("class", "text t_3 input-validation-error");
                        }
                    } else {
                        $("#txtEmail").attr("class", "text t_3");
                        errorElement.children().remove();
                        errorElement.hide()
                    }
                });

                request.fail(function (jqXHR, textStatus) {
                    ShowDialogMessage("warn", textStatus);
                });
            }
        });

        $("#txtConfirmedPass").blur(function () {
            var errorElement = $("#confirmError");
            if ($("#txtConfirmedPass").val() != $("#txtPassword").val()) {
                //.next('span.field-validation-error va');
                if (errorElement) {
                    errorElement.removeClass("field-validation-valid va");
                    errorElement.addClass("field-validation-error");
                    errorElement.append('<span htmlfor="txtModality" generated="true" class="" style="">密码不一致</span>');
                    errorElement.show();
                    $("#txtConfirmedPass").attr("class", "text t_3 input-validation-error");

                }
            } else {
                $("#txtConfirmedPass").attr("class", "text t_3");
                errorElement.children().remove();
                errorElement.hide();
            }
        });

        $('input[type="checkbox"][name="chkShow"]').change(function () {
            if ($('input[type="checkbox"][name="chkShow"]').attr("checked")) {
                $("#divDetail").toggle(1000, null, true);
            } else {
                $("#divDetail").toggle(1000, null, false);
            }
        });

        $('input[type="checkbox"][name="chkAgree"]').change(function () {
            if ($('input[type="checkbox"][name="chkAgree"]').attr("checked")) {

                $("#btnRegisterSubmit").removeAttr("disabled");
            } else {
                $("#btnRegisterSubmit").attr("disabled", "disabled");
            }
        });


        $("#ddlProvince").change(function () {
            var pro = $("#ddlProvince").find("option:selected").val();
            if (pro != "请选择" && pro != "") {
                var errorElement = $("#locationError");
                errorElement.children().remove();
                errorElement.hide()
            }
        });

        $("#ddlMarriage").change(function () {
            var pro = $("#ddlMarriage").find("option:selected").val();
            var errorElement = $("#maggrigeError");
            if (pro != "请选择" && pro != "") {

                errorElement.children().remove();
                errorElement.hide()
            } else {
                errorElement.removeClass("field-validation-valid");
                errorElement.append('<span htmlfor="" generated="true" class="" style="">请选择婚姻状况</span>');
                errorElement.show();
            }
        });

        $("#ddlGender").change(function () {
            var pro = $("#ddlGender").find("option:selected").val();
            var errorElement = $("#genderError");
            if (pro != "请选择" && pro != "") {

                errorElement.children().remove();
                errorElement.hide()
            } else {
                errorElement.removeClass("field-validation-valid");
                errorElement.append('<span htmlfor="ddlGender" generated="true" class="" style="">请选择性别</span>');
                errorElement.show();
            }
        });


        $("#btnRegisterSubmit").click(function () {

            if ($('input[type="checkbox"][name="chkAgree"]').attr("checked")) {
                var pro = $("#ddlProvince").find("option:selected").val();
                var errorElement = $("#locationError");
                if (pro == "请选择" || pro == "") {
                    if (errorElement) {
                        errorElement.removeClass("field-validation-valid");
                        errorElement.addClass("field-validation-error");
                        errorElement.append('<span htmlfor="" generated="true" class="" style="">请选择现居住地</span>');
                        errorElement.show();
                        //$("#txtAccount").attr("class", "text t_3 input-validation-error");
                    }
                } else {
                    //$("#txtAccount").attr("class", "text t_3");
                    errorElement.children().remove();
                    errorElement.hide()
                }

                var maggrige = $("#ddlMarriage").find("option:selected").val();
                var maggrigeError = $("#maggrigeError");
                if (maggrige == "请选择" || maggrige == "") {
                    if (maggrigeError) {
                        maggrigeError.removeClass("field-validation-valid");
                        maggrigeError.addClass("field-validation-error");
                        maggrigeError.append('<span htmlfor="" generated="true" class="" style="">请选择婚姻状况</span>');
                        maggrigeError.show();
                    } else {
                        maggrigeError.children().remove();
                        maggrigeError.hide()
                    }
                }

                var gender = $("#ddlGender").find("option:selected").val();
                var genderError = $("#genderError");
                if (gender == "请选择" || gender == "") {
                    if (genderError) {
                        genderError.removeClass("field-validation-valid");
                        genderError.addClass("field-validation-error");
                        genderError.append('<span htmlfor="" generated="true" class="" style="">请选择性别</span>');
                        genderError.show();
                    } else {
                        genderError.children().remove();
                        genderError.hide()
                    }
                }

            } else {

                //$("#btnRegisterSubmit").attr("disabled", "disabled");
                //$('#dialog').dialog('open');
                ShowDialogMessage("warn", "请同意服务条款，才能注册！");


                return false;
            }
        });




        $(function () {
            $("#txtBirthday").datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, minDate: null, maxDate: null, yearRange: 'c-50:c+20', onSelect: function (dateText, inst) { calculateAge(dateText); }, onClose: function () { $("#txtBirthday").datepicker("hide"); var errorElement = $("#txtBirthday").next('span.field-validation-error'); if (errorElement) { errorElement.children().remove(); errorElement.hide(); $("#txtBirthday").attr("class", "text t_3"); } } });
        });

        function calculateAge(dateText) {
            var now = new Date();
            var birthday = parseDate(dateText);
            var age = now.getFullYear() - birthday.getFullYear();
            $("#txtAge").val(age - 1);
        }

        function parseDate(str) {
            if (typeof str == 'string') {
                var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);
                if (results && results.length > 3)
                    return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]));
                results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);
                if (results && results.length > 6)
                    return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]));
                results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);
                if (results && results.length > 7)
                    return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]), parseInt(results[7]));
            }
            return null;
        }


        $('#openservice').click(function () {

            $("#service_dialog").dialog(
	{
	    modal: true,
	    buttons: {
	        拒绝: function () {
	            $('input[type="checkbox"][name="chkAgree"]').removeAttr("checked");
	            $("#btnRegisterSubmit").attr("disabled", "disabled");
	            $(this).dialog("close");
	        },
	        同意: function () {
	            $('input[type="checkbox"][name="chkAgree"]').attr("checked", "checked");
	            $("#btnRegisterSubmit").removeAttr("disabled");
	            $(this).dialog("close");
	        }

	    },
	    width: 900,
	    height: 600
	}
	);
            return false;
        });
        $("#service_dialog").load("/Account/ShowRegisterNotice");
    });
</script>
<!--弹出提示框html内容-->
<div id="service_dialog" style="display: none;" title="都来米会员注册条款">
</div>
<!--弹出提示框html内容已结束-->
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { id = "formRegister" }))
{
    <div class="main register">
        <div class="main_tab_2">
            <div class="main_tab_2_up">
                <ul>
                    <li class="current"><a href="#">注册账号</a></li>
                </ul>
            </div>
            <div class="main_tab_2_down">
                <div class="box">
                    <h3>
                        基本资料<a href="#"></a></h3>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s></s>&nbsp;</label>
                        <div class="info">
                            @Html.ValidationSummary(true, "账号注册失败，请检查错误信息并重试！")
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("昵称")</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.Account.AccountName, new { @class = "text t_3", maxlength = 24, id = "txtAccount" })
                            <span>6-15位数字，字母和下划线</span>
                            @Html.ValidationMessageFor(model => model.Account.AccountName, "", new { id = "accountError" })
                            @*<div class="va error"></div>*@
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("登录密码")</label>
                        <div class="info">
                            @Html.PasswordFor(model => model.Account.Password, new { @class = "text t_3", maxlength = 18, id = "txtPassword" })
                            
                              <span>6-18位的字符</span>
                            @Html.ValidationMessageFor(model => model.Account.Password, "", new { @class = "va error" })
                            <div class="va error" style="display: none;">
                                请输入密码</div>
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("确认密码")</label>
                        <div class="info">
                            @Html.PasswordFor(model => model.ConfirmedPassword, new { @class = "text t_3",id="txtConfirmedPass", maxlength = 18 })
                            @Html.ValidationMessageFor(model => model.ConfirmedPassword, "", new { @class = "va error",id = "confirmError" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("邮箱")</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.Account.Email, new { @class = "text t_3", maxlength = 30, id = "txtEmail" })
                            @Html.ValidationMessageFor(model => model.Account.Email, "", new { id = "emailError" })
                         
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("现居住地")</label>
                        <div class="info">
 
                            @{ Html.RenderPartial("_CountrySelection", new DLM.Web.ViewModel.CountrySelectionPageView());}
                            @Html.ValidationMessageFor(model => model.User.Location, "", new { @class = "va error", id = "locationError" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("婚姻状况")</label>
                        <div class="info">
                            @Html.DropDownListFor(model => model.User.Marriage, new List<SelectListItem> 
                        { new SelectListItem { Text = "请选择", Value = "" },
                            new SelectListItem { Text = "未婚", Value = "未婚" },
                            new SelectListItem { Text = "已婚", Value = "已婚" }, new SelectListItem { Text = "离异", Value = "离异" }}, new { @class = "select", id = "ddlMarriage" })
                                 @Html.ValidationMessageFor(model => model.User.Marriage, "", new { @class = "va error", id = "maggrigeError" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("性别")</label>
                        <div class="info">
                            @Html.DropDownListFor(model => model.User.Gender, new List<SelectListItem> 
                        { new SelectListItem { Text = "请选择", Value = "" },
                            new SelectListItem { Text = "男", Value = "False" },
                            new SelectListItem { Text = "女", Value = "True" } }, new { @class = "select", id = "ddlGender" })
                                   @Html.ValidationMessageFor(model => model.User.Gender, "", new { @class = "va error", id = "genderError" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("出生日期")</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.User.Birthday, new { @class = "text t_3", maxlength = 15, id = "txtBirthday" })
                            @Html.ValidationMessageFor(model => model.User.Birthday)
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s>*</s>@Html.Label("年龄")</label>
                        <div class="info">
                            @Html.TextBoxFor(model => model.User.Age, new { @class = "text t_3", maxlength = 4, id = "txtAge" })
                            @Html.ValidationMessageFor(model => model.User.Age, "", new { @class = "va error" })
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s></s>&nbsp;</label>
                        <div class="info">
                            <input type="checkbox" name="chkShow" id="chkShow" class="checkbox" />我对单身交友感兴趣
                        </div>
                    </div>
                    <div id="divDetail" style="display: none;">
                        <h3>
                            详细信息<a href="#"></a></h3>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("籍贯")</label>
                            <div class="info">
                                  @{ Html.RenderPartial("_NativeSelection", new DLM.Web.ViewModel.NativeSelectionPageView());}
                               @* @Html.TextBoxFor(model => model.User.NativePlace, new { @class = "text t_3", maxlength = 16})*@
                                @Html.ValidationMessageFor(model => model.User.NativePlace, "", new { @class = "va error" })
                            </div>
                        </div>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("身高")</label>
                            <div class="info">
                                @Html.TextBoxFor(model => model.User.Stature, new { @class = "text t_3", maxlength = 10 })
                                @Html.ValidationMessageFor(model => model.User.Stature, "", new { @class = "va error" })厘米</div>
                        </div>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("体重")</label>
                            <div class="info">
                                @Html.TextBoxFor(model => model.User.Weight, new { @class = "text t_3", maxlength = 8 })
                                @Html.ValidationMessageFor(model => model.User.Weight, "", new { @class = "va error" })公斤</div>
                        </div>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("教育状况")</label>
                            <div class="info">
                                @{
                                     List<SelectListItem> eduList = new List<SelectListItem> 
    {new SelectListItem { Text = "请选择", Value = "" },
        new SelectListItem{ Text="高中",Value="高中"},
        new SelectListItem{ Text="大专",Value="大专"},
        
           new SelectListItem{Text="本科",Value="本科"},new SelectListItem{ Text="硕士",Value="硕士"},new SelectListItem{ Text="博士",Value="博士"},
    };

                                }
                                @Html.DropDownListFor(m => m.User.Education, eduList, new { @class = "sel" })
                                @Html.ValidationMessageFor(model => model.User.Education, "", new { @class = "va error" })
                            </div>
                        </div>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("工作")</label>
                            <div class="info">
                                @Html.TextBoxFor(model => model.User.Job, new { @class = "text t_3", maxlength = 20 })
                                @Html.ValidationMessageFor(model => model.User.Job, "", new { @class = "va error" })
                            </div>
                        </div>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("月收入(税前)")</label>
                            <div class="info">
                                @{
                                     List<SelectListItem> incomeList = new List<SelectListItem> 
    {new SelectListItem { Text = "请选择", Value = "" },
        new SelectListItem{ Text="5000及以下",Value="5000及以下"},
           new SelectListItem{Text="5000-10000",Value="5000-10000"},new SelectListItem{ Text="10000-20000",Value="10000-20000"},
           new SelectListItem{ Text="20000以上",Value="20000以上"}
    };
                                }
                                @Html.DropDownListFor(model => model.User.Income, incomeList, new { @class = "sel" })
                                @Html.ValidationMessageFor(model => model.User.Income, "", new { @class = "va error" })</div>
                        </div>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("房车状况")</label>
                            <div class="info">
                                @{
                                     List<SelectListItem> carList = new List<SelectListItem> 
    {new SelectListItem{ Text="请选择",Value=""},
        new SelectListItem{ Text="有房有车",Value="有房有车"},
           new SelectListItem{Text="无房无车",Value="无房无车"},
           new SelectListItem{ Text="无房有车",Value="无房有车"},
           new SelectListItem{ Text="有房无车",Value="有房无车"}
    };
                                }
                                @Html.DropDownListFor(m => m.User.Car, carList, new { @class = "sel" })
                                @Html.ValidationMessageFor(model => model.User.Car, "", new { @class = "va error" })</div>
                        </div>
                        <div class="tr clearfix">
                            <label class="lb">
                                <s></s>@Html.Label("父母状况")</label>
                            <div class="info">
                                @{
                                     List<SelectListItem> faList = new List<SelectListItem> 
    {new SelectListItem{ Text="请选择",Value=""},
        new SelectListItem{ Text="均健在",Value="均健在"},
           new SelectListItem{Text="母亲健在",Value="母亲健在"},
           new SelectListItem{ Text="父亲健在",Value="父亲健在"},
           new SelectListItem{ Text="其他",Value="其他"}
    };

                                }
                                @Html.DropDownListFor(model => model.User.Parents, faList, new { @class = "sel" })
                                @Html.ValidationMessageFor(model => model.User.Parents, "", new { @class = "va error" })</div>
                        </div>
                        <h3>
                            <a href="#"></a>
                        </h3>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s></s>请输入验证码</label>
                        <div class="info">
                            <div>
                                @Html.MvcCaptcha()
                                <span id="captchaImage"></span>
                                <br />
                                <br />
                                <input type="text" name="_mvcCaptchaText" id="_mvcCaptchaText", maxlength="4" />
                                </div>
                        </div>
                    </div>
                    <div class="tr clearfix">
                        <label class="lb">
                            <s></s>&nbsp;</label>
                        <div class="info">
                            <input type="checkbox" class="checkbox" id="chkAgree" name="chkAgree" />我已阅读并同意<a
                                href="#" id="openservice">服务条款</a></div>
                    </div>
                    <div class="tr clearfix btn">
                        <label class="lb">
                            <s></s>&nbsp;</label>
                        <div class="info">
                            <input type="submit" value="" class="register" id="btnRegisterSubmit" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}
